package com.bluemor.reddotface.view;

import com.bluemor.reddotface.R;
import com.bluemor.reddotface.activity.AngelCommentActivity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.Animation.AnimationListener;
import android.widget.ImageView;

public class AngelDetailFragment1 extends Fragment implements OnClickListener{
	private ImageView imageView_word,imageView_showdown;
	
	public static AngelDetailFragment1 getInstance(){
		AngelDetailFragment1 fragment = new AngelDetailFragment1();
		return fragment;
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.angeldetail_fragment1_layout, container, false);
		imageView_word = (ImageView) view.findViewById(R.id.imageview_word);
		imageView_showdown = (ImageView) view.findViewById(R.id.angel_showdown);
		imageView_showdown.setOnClickListener(this);
		Animation animation = AnimationUtils.loadAnimation(getActivity(), R.anim.movein);
		imageView_word.startAnimation(animation);
		return view;
	}

	@Override
	public void onClick(View v) {
		Intent intent = new Intent(getActivity(), AngelCommentActivity.class);
		startActivity(intent);
	}
	
	@Override  
	public void setUserVisibleHint(boolean isVisibleToUser) {  
	    super.setUserVisibleHint(isVisibleToUser);  
	    if (isVisibleToUser) {  
	    		Log.e("savvy", "setUserVisibleHint");
	        //相当于Fragment的onResume 
	    	Animation animation = AnimationUtils.loadAnimation(getActivity(), R.anim.movein);
	    	animation.setAnimationListener(new AnimationListener() {
				
				@Override
				public void onAnimationStart(Animation animation) {
				
					
				}
				
				@Override
				public void onAnimationRepeat(Animation animation) {
					// TODO Auto-generated method stub
					
				}
				
				@Override
				public void onAnimationEnd(Animation animation) {
					imageView_word.setVisibility(View.VISIBLE);
					
				}
			});
	    	if(imageView_word!=null){
	    	imageView_word.startAnimation(animation);
	    	}
	    } else {  
	        //相当于Fragment的onPause  
	    	Log.e("savvy", "onPause");
	    	if(imageView_word!=null){
	    		imageView_word.setVisibility(View.GONE);
	    	}
	    }  
	    
	}  
}
